<?php

namespace App\Http\Controllers;

use App\Admin\Controllers\BusinessController;
use App\Http\Resources\BusinessCollection;
use App\Models\Business;
use App\Models\BusinessType;
use Illuminate\Http\Request;

class BusineController extends Controller
{
    public function type()
    {
        return [
            'code' => 200,
            'message' => '请求成功',
            'data' => BusinessType::all()
        ];
    }

    public function  list(Request $request)
    {
        $type = $request->input('type');
        $pageSize = $request->input('page_size');
       $business=  Business::when($type, function ($query) use ($type) {
            $query->where('bussine_type_id', $type);
        })->paginate($pageSize);
        return new BusinessCollection($business);

    }
    public function detail(Request $request)
    {
        $id = $request->input('id');
        $business = Business::findOrFail($id);
        return [
            'code' => 200,
            'message' => '请求成功',
            'data' => [
                'id' => $business->id,
                'title' => $business->title,
                'logo' => \Storage::url($business->logo),
                'type_name' => $business->type->name,
                'type_id' => $business->bussine_type_id,
                'price' => $business->price,
                'xiaofei' => $business->xiaofei,
                'chanpin' => $business->chanpin,
                'city' => $business->city,
            ]
        ];
    }
}
